package com.best.onegous.Adapter;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import com.best.onegous.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class UserAdapter extends BaseAdapter{
	Intent intent;
	private int setitem=1;
	int TYPE = 0;  
	protected ImageLoader imageLoader = ImageLoader.getInstance();
	  private List<JSONObject> data = new ArrayList<JSONObject>();  
	    private LayoutInflater layoutInflater;  
	    private Context context;  
	    public UserAdapter(Context context, List<JSONObject> data) {  
	    	imageLoader.init(ImageLoaderConfiguration.createDefault(context));
	        this.context = context;  
	        this.data = data;  
	        this.layoutInflater = LayoutInflater.from(context);  
	    }     
	@Override
	public int getCount() {
		// TODO Auto-generated method stub

		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub

		return data.get(position);
	}

	@Override
	public long getItemId(int position) { 
		// TODO Auto-generated method stub
		return position;
	}
	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		
		return 3;
	}
	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		
			if(0==TYPE){
				return 0;
			}else if(1==TYPE){
				return 1;
			}else if(2==TYPE){
				return 2;
			}

		return super.getItemViewType(position);
	}
	public void setItem(int item){
		TYPE = item;
		notifyDataSetChanged();
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		ViewHome viewhome=null;
		ViewHome2 viewhome2=null;
		ViewHome3 viewhome3=null;
		int type = getItemViewType(position);  
		 if (convertView == null) {  
			 switch (type) {
			case 0:
				viewhome = new ViewHome();
				convertView = layoutInflater.inflate(R.layout.user_one_item, null);
			/*	viewhome.jiexiao = (LinearLayout) convertView.findViewById(R.id.jiexiao);
				viewhome.jinxing = (LinearLayout) convertView.findViewById(R.id.jinxing);
				viewhome.title = (TextView) convertView.findViewById(R.id.title);
				viewhome.name = (TextView) convertView.findViewById(R.id.name);
				viewhome.xingyunma = (TextView) convertView.findViewById(R.id.xingyunma);
				viewhome.titles = (TextView) convertView.findViewById(R.id.titles);
				viewhome.yicanyu = (TextView) convertView.findViewById(R.id.yicanyu);
				viewhome.zongxu = (TextView) convertView.findViewById(R.id.zongxu);
				viewhome.shengyu = (TextView) convertView.findViewById(R.id.shengyu);
				viewhome.pd = (TextView) convertView.findViewById(R.id.pd);
				viewhome.img = (ImageView) convertView.findViewById(R.id.img);
				viewhome.mediacontroller_seekbar = (MySeekBar) convertView.findViewById(R.id.mediacontroller_seekbar);*/
				convertView.setTag(viewhome);
				break;
			case 1:
				viewhome2 = new ViewHome2();
				convertView = layoutInflater.inflate(R.layout.user_two_item, null);
				/*viewhome2.img = (ImageView) convertView.findViewById(R.id.img);
				viewhome2.name = (TextView) convertView.findViewById(R.id.name);
				viewhome2.xingyunma = (TextView) convertView.findViewById(R.id.xingyunma);
				viewhome2.time = (TextView) convertView.findViewById(R.id.time);*/
				convertView.setTag(viewhome2);
				break;
			case 2:
				viewhome3 = new ViewHome3();
				convertView = layoutInflater.inflate(R.layout.shaidan_item, null);
				/*viewhome3.name = (TextView) convertView.findViewById(R.id.name);
				viewhome3.time = (TextView) convertView.findViewById(R.id.time);
				viewhome3.neirong = (TextView) convertView.findViewById(R.id.neirong);
				viewhome3.shoucang = (TextView) convertView.findViewById(R.id.shoucang);
				viewhome3.pinglun = (TextView) convertView.findViewById(R.id.pinglun);
				viewhome3.allimg = (LinearLayout) convertView.findViewById(R.id.allimg);
				viewhome3.img1 = (ImageView) convertView.findViewById(R.id.img1);
				viewhome3.img2 = (ImageView) convertView.findViewById(R.id.img2);
				viewhome3.img3 = (ImageView) convertView.findViewById(R.id.img3);*/
				
				
				convertView.setTag(viewhome3);
				break;
			}
		 }else{
			 switch (type) {
			case 0:
				viewhome = (ViewHome) convertView.getTag();
				break;
			case 1:
				viewhome2 = (ViewHome2) convertView.getTag();
				break;
			case 2:
				viewhome3 = (ViewHome3) convertView.getTag();
				break;
			}
		 }
		// final JSONObject item = data.get(position);
		 switch (type) {
		 case 0:
			
			
				break;
			case 1:
			
				break;
			case 2:
				
				break;
		default:
			break;
		}
		 
		 
	
			
			return convertView;
		}
	
	 class ViewHome{  
		    private LinearLayout jiexiao,jinxing;
		    private TextView title,name,xingyunma,titles,yicanyu,zongxu,shengyu,pd;
		    
		    private ImageView img;
		   
		    
		}
	 class ViewHome2{  
		 private ImageView img;
		 
		 private TextView name,xingyunma,time;
		    
		}
	 class ViewHome3{  
		 private TextView name,time,neirong,shoucang,pinglun;
		    private LinearLayout allimg;
		    private ImageView img1,img2,img3;
		    
		}
	}